/*
 * @Author: Jiarun
 * @Date: 2021-06-01 13:39:35
 * @LastEditors: Jiarun
 * @LastEditTime: 2021-06-08 08:55:15
 * @Description: 
 */
#ifndef __ES_GPIO_H
#define __ES_GPIO_H

#ifdef __cplusplus
 extern "C" {
#endif

#include "stm32f10x_gpio.h"

/**
	* 位带操作 BitBand，实现思想参考<<CM3权威指南>>
	* BIT_ADDR(GPIOA_ODR_Addr,n)
    * BIT_ADDR(GPIOA_IDR_Addr,n)
	*/
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum))

#define PIN_IN(GPIOx, pin_num)		(BIT_ADDR(GPIOx+0x8, pin_num))
#define PIN_OUT(GPIOx, pin_num)		(BIT_ADDR((uint32_t)GPIOx+0xC, pin_num))


void gpio_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIOMode_TypeDef GPIO_Mode);


#ifdef __cplusplus
}
#endif

#endif /* __ES_GPIO_H */
